/*
 * Phase.cpp
 *
 *  Created on: 16/10/2011
 *      Author: godinho
 */

#include <localview/Phase.h>
#include <log.h>

std::string Phase::TAG = "Phase";

Phase::Phase() {
}

Phase::~Phase() {
}

int Phase::addLink(Link* link) {
	mLinks.push_back(link);
}

int Phase::getLinkCount() {
	return mLinks.size();
}

void Phase::setStatus(const char* status) {
	for(int i = 0; status[i]; i++) {
		switch(status[i]) {
		case 'g':
		case 'G':
			setStatus(i, Phase::GREEN);
			break;
		case 'y':
			setStatus(i, Phase::YELLOW);
			break;
		case 'r':
			setStatus(i, Phase::RED);
			break;
		default:
			rsi::log(Phase::TAG, __FILE__, __LINE__, "Cannot find definition to traffic light status: %c", status[i]);
		}
	}
}

void Phase::setStatus(int linkIndex, LIGHTS status) {
	mStatus[linkIndex] = status;
}

Phase::LIGHTS Phase::getStatus(int index) {
	return mStatus[index];
}

int Phase::getDuration() {
	return mDuration;
}

void Phase::setDuration(int d) {
	mDuration = d;
}

std::vector<Link*> Phase::getLinks() {
	return mLinks;
}
